var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var base64 = require('../../utils/Base64.js');
var app = getApp();

var uid = 0;
var token = '';

var wxAuthFail = true;
var inviteuid = '';


Page({

  /**
   * 页面的初始数据
   */
  data: {


    uid: 0,
    token: '',
    openid: '',
    web_view_url:'',


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (data) {
    console.log("data==",data);

    var webUrl = base64.decode(data.weburl);
    this.setData({
      web_view_url: webUrl
    })
    console.log("网页地址：" + this.data.web_view_url);



    var tc = app.get_tc();
    var titlename = tc == 1 ? '澳门佳作' : '澳门佳作';
    wx.setNavigationBarTitle({
      title: titlename, 
    })
    var that = this;
    inviteuid = data.inviteuid ? data.inviteuid : ''; 
    that.getLoginInfo(inviteuid);

 


 
  },

  getLoginInfo: function (inviteuid) {
    var that = this;
    app.LoginUserInfo(function (res) {
      console.log("mine login:", res);
      wxAuthFail = res == -1;//用户拒绝授权
      if (wxAuthFail) {
        return;
      }
      that.setData({
        uid: res.uid,
        token: res.token,
        url : that.data.web_view_url
      });
      console.log(res.uid);
      var id = inviteuid ? inviteuid : res.uid;
      util.api({
        data: {
          "uid": id,
          "publickey": util.publiccode,
          "ac": "userinfo",
          //"tc": that.data.tc
        },
        success: function (responseData) {
          console.log("用户信息", responseData.data);
          that.setData({
            userinfo: responseData.data
          });
        }
      });

    });
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },



})